package com.movitech.mobile.cz.base.supplier.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.movitech.mobile.cz.base.common.util.DateUtils;
import com.movitech.mobile.cz.base.common.util.StringUtils;
import com.movitech.mobile.cz.base.supplier.entity.SSuppliersLastThreeAchieve;
import com.movitech.mobile.cz.base.supplier.entity.ext.ExtSSuppliersLastThreeAchieve;
import com.movitech.mobile.cz.base.supplier.mapper.SSuppliersLastThreeAchieveMapper;
import com.movitech.mobile.cz.base.supplier.mapper.ext.ExtSSuppliersLastThreeAchieveMapper;
import com.movitech.mobile.cz.base.supplier.service.SSuppliersLastThreeAchieveService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/**
 * <p>
 * 供方近三年业绩 服务实现类
 * </p>
 *
 * @author Movitech Mobile
 * @since 2018-02-28
 */
@Service("sSuppliersLastThreeAchieveService")
@Transactional
public class SSuppliersLastThreeAchieveServiceImpl extends ServiceImpl<SSuppliersLastThreeAchieveMapper, SSuppliersLastThreeAchieve> implements SSuppliersLastThreeAchieveService {
    @Autowired
    private ExtSSuppliersLastThreeAchieveMapper extSSuppliersLastThreeAchieveMapper;

    @Override
    public List<SSuppliersLastThreeAchieve> selectValidData() {
        Date date = DateUtils.getNow();
        EntityWrapper entityWrapper = new EntityWrapper();
//        entityWrapper.eq("source_type",1).eq("del_flag",0).and(
//                "cooperative_start_time<={0}",date
//        ).and("cooperative_end_time>={0}",date);
        entityWrapper.eq("source_type",2).eq("del_flag",0).eq("contact_status",2).isNotNull("cooperative_project_id");
        return selectList(entityWrapper);
    }

    @Override
    public ExtSSuppliersLastThreeAchieve findExtById(String id) {
        return extSSuppliersLastThreeAchieveMapper.findExtById(id);
    }

    @Override
    public List<ExtSSuppliersLastThreeAchieve> findExtList(Page<ExtSSuppliersLastThreeAchieve> page,ExtSSuppliersLastThreeAchieve  extSSuppliersLastThreeAchieve) {
        return extSSuppliersLastThreeAchieveMapper.findExtList(page,extSSuppliersLastThreeAchieve);
    }

    @Override
    public List<SSuppliersLastThreeAchieve> findSimListByName(String name) {
        EntityWrapper entityWrapper = new EntityWrapper();
        entityWrapper.setSqlSelect("id,contact_name").like("contact_name",name).eq("source_type",2).isNotNull("cooperative_project_id");
        return selectPage(new Page<SSuppliersLastThreeAchieve>(1,50),entityWrapper).getRecords();
    }

    @Override
    public List<SSuppliersLastThreeAchieve> findOutSimListByName(String name,String supplierId) {
        EntityWrapper entityWrapper = new EntityWrapper();
        entityWrapper.setSqlSelect("id,cooperative_project_name,sign_contact_price,actual_contact_price").eq("suppliers_id",supplierId)
                .eq("cooperative_type",1).eq("source_type",0).isNotNull("cooperative_project_name").and("cooperative_project_name!=''");
        if(StringUtils.isNotEmpty(name)){
            entityWrapper.like("cooperative_project_name",name);
        }
        return selectList(entityWrapper);
    }
}
